package com.rjt.user.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.rjt.user.model.UserModel;
import com.rjt.user.service.UserService;

@Controller
@RequestMapping("user")
public class LoginController {
	
	@Autowired
	private UserService userService;
	
	@PostMapping("login")
	@ResponseBody
	public String login(String email,String password,HttpServletRequest request) {
		return userService.login(email,password,request);
	}
	
	@PostMapping("register")
	@ResponseBody
	public String register(UserModel userModel) {
		return userService.register(userModel);
	}
	
	@PostMapping("checkUser")
	@ResponseBody
	public String checkUser(UserModel userModel) {
		return userService.checkUser(userModel);
	}
	

	@GetMapping("toLogin")
	public String toLogin(HttpSession session) {
		session.removeAttribute("user");
		return "user/login";
	}
	
	@GetMapping("toRegister")
	public String toRegister() {
		return "user/register";
	}
   
	@GetMapping("error")
	public String toError() {
		return "common/error";
	}
	
	
}
